<?php
/* 
 * class.index.php
 * 碎碎念首页
 * @author samuel
 * @date 2009-05-22
 */
include_once 'class.mytalkBase.php';
class mytalk_index extends mytalkBase {

    function  __construct($core) {
        parent::__construct();
        //参数处理
        $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 0;
	    $this->page = $this->params['page'] ? (int)$this->params['page'] : 1;
	    $this->type = $this->params['type'] ? strtolower(trim($this->params['type'])) : 'all';
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }

        $run = "run_" . $this->step;
        
        //header("Content-type: text/vnd.wap.wml");
        $this->$run();
    }

    function run_index(){
        //WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "碎碎念-信息动态";
	    $posturl = $_SERVER['PHP_SELF']."?uid=".$this->user_id."step=talk_do";
	    $content = "";
	    $content .= "你正在做什么<br/>";
	    $content .= "<input type='text' name='mytalk' value='' maxlength='20' size='15' />";
        $content .= "<anchor title=\"碎一下\">碎一下<go href=\"".$posturl."\" method=\"post\">
                    <postfield name=\"type\" value=\"talk\" />
                    <postfield name=\"mytalk\" value=\"$(mytalk)\" />
                    </go></anchor><br/><br/>";
          
        
        
        
        $newFollowCount = $this->getUserNewTalkFollow($this->user_id, true);

        $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."'>刷</a>!
                    <a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&type=new'>新(".$newFollowCount.")</a>!
                    <a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&type=atten'>关注</a>|
                    <a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&type=friend'>好友</a>|<br/>";
        
        $pagesize = 10;
	    $displaypage = 5;
	    $page = $this->page;
	    $current_url = $_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=".$this->type;


        $arr_filter= array();
        $arr_filter[] = array('attr'=>'uTalkUserID', 'value'=>$this->user_id, 'oper'=>'=');
        $arr_order = array('attr'=>'uPublishTime', 'order'=>'DESC');
        $arr_limit = array('offset'=>($page-1)*$pagesize, 'pagesize'=>$pagesize, 'url'=>'');
        if($this->type=='new'){
            $arr_filter[] = array('attr'=>'uIsRead', 'value'=>'1', 'oper'=>'=');
        }elseif($this->type == 'atten'){
            
        }elseif($this->type == 'friend'){
            
        }


        $counts = $this->getUserAllTalkInfo($arr_filter, $arr_order, $arr_limit, true);
        //var_dump($counts);
        $totalPages = ceil($counts/$pagesize);
        $pager = $this->core->utility->wap_pager($totalPages, $page, $displaypage, $current_url);

        $arr_info = $this->getUserAllTalkInfo($arr_filter, $arr_order, $arr_limit, false);
        if(is_array($arr_info) && count($arr_info)){
            foreach($arr_info as $info){
                $talkUser = $this->core->load('user::userBase')->getInfo(array('table'=>'fun_user', 'primary'=>'UserID'),$info['uTalkUserID']);
                $atime = $info['uPublishTime'];
                $atime_format = $this->formatTalkTime($atime);
                if(!$info['uTalkFollowID']){
                    $content .= "<a href=''>".$talkUser['UserNickName']."</a> ".$info['uTalkContent'];
                    $content .= "|".$atime_format."|<a href=''>删除</a><br/>";
                }else{
                    $followUser = $this->core->load('user::userBase')->getInfo(array('table'=>'fun_user', 'primary'=>'UserID'),$info['uUserID']);
                    $content .= "<a href=''>".$followUser['UserNickName']."</a>@<a href=''>".$talkUser['UserNickName']."</a> ".$info['uTalkContent'];
                    $content .= "|".$atime_format."|<a href=''>删除</a>(<a href=''>回复</a>)<br/>";
                }
            }
        }
        

	
	    $content .= "<br/>";
	    $myAttentionCount = $this->getUserAttention($this->user_id, '', true);
	    $attentionMeCount = $this->getuserAttention('', $this->user_id, true);
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=meAttention&amp;uid=".$this->user_id."'>我关注的(".(int)$myAttentionCount.")</a>|<a href='".$_SERVER['PHP_SELF']."?act=attentionMe&amp;uid=".$this->user_id."'>关注我的(".(int)$attentionMeCount.")</a><br/>";
	
	    $content .= "<br/><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    
    }
}


?>
